package comps
{
	import controls.ConfigArea;
	
	import flash.display.DisplayObject;
	
	import mx.containers.HBox;
	import mx.containers.Panel;
	import mx.controls.Image;
	import mx.controls.Label;
	
	import utils.NameConvertor;	
	public class CompTemplate extends Panel
	{
		public var success:Boolean=false;
		[Embed("close.gif")]
		private var closeSquare:Class;
		
		public var comp:Object=null;
		
		private var myHbox:HBox;
		private var close:Image;
		private var msg:Label;
		private var compName:String=null;
		
		private var container:ConfigArea=null;		
		public function CompTemplate(compName:String="ymap", con:ConfigArea=null){
			super();
			this.compName=compName;
			this.title=NameConvertor.shortName2LongName(compName);
			this.container=con;
			initiateBody();
		}
		public function showMatchingPoint(dataType:String,codeWord:String):Boolean{
			return comp.showMatchingPoint(dataType, codeWord);	
		}
		private function initiateBody():void{
			if(compName==null)
				return;			
			switch(compName){
				case "ymap":
					comp=new YahooMaps();															
					YahooMaps(comp).configArea=this.container;
					YahooMaps(comp).wrapper=this;
					break;
				case "tbox":
					comp=new TextComp();
					TextComp(comp).configArea=this.container;
					TextComp(comp).wrapper=this;
					break;
				default:
					break;
			}
			if(comp!=null) this.success=true;
		}
		override protected function createChildren() : void{
			super.createChildren();
			close = new Image();
			close.source = closeSquare;
			close.width = 18;
			close.height = 18;
			msg=new Label();
			msg.text="haha";
			myHbox = new HBox( );
			myHbox.addChild(close);
			myHbox.addChild(msg);
			this.titleBar.addChild( myHbox );
			if(comp){												
				this.addChild(DisplayObject(comp));	
				this.success=true;
			}
		}
		override protected function updateDisplayList (unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			myHbox.setActualSize( myHbox.getExplicitOrMeasuredWidth(),
				myHbox.getExplicitOrMeasuredHeight() );
			var y:int = 4;
			var x:int = this.width - myHbox.width - 12;
			myHbox.move(x, y);
		}
	}
}